package utils;

public class Vector3 {
    public Double x;
    public Double y;
    public Double z;

    public Vector3(Double x, Double y, Double z) {
        this.x = x;
        this.y = y;
        this.z = z;
    }

    public Vector3(Double[] start, Double[] end) {
        this.x = end[0] - start[0];
        this.y = end[1] - start[1];
        this.z = start.length == 2 ? 0 : end[2] - start[2];
    }

    /**
     * Dot Operation
     *
     * @param v1 vector1
     * @param v2 vector2
     * @return Dot Result.
     */
    public static Double Dot(Vector3 v1, Vector3 v2) {
        return v1.x * v2.x +
                v1.y * v2.y +
                v1.z * v2.z;
    }

    /**
     * Cross Operation
     *
     * @param v1 vector1
     * @param v2 vector2
     * @return Cross Result Vector.
     */
    public static Vector3 Cross(Vector3 v1, Vector3 v2) {
        return new Vector3(
                v1.y * v2.z - v1.z * v2.y,
                v1.z * v2.x - v1.x * v2.z,
                v1.x * v2.y - v1.y * v2.x);
    }

    public Double length() {
        return Math.sqrt(x * x + y * y + z * z);
    }

}
